﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq;

namespace Ex05
{
    class Program
    {
        static void Main(string[] args)
        {
            // The following example uses DataLoadOptions for filtering. To see its effect, first highlight
            // just the foreach loop, and execute that, then execute the entire query for comparison:
            var db = new NorthwindDataContext();

            var options = new DataLoadOptions();
            options
                .AssociateWith<Customer>(
                c => c.Purchases.Where(p => p.Price > 1000));
            db.LoadOptions = options;

            foreach (Customer c in db.Customers)
            {
                Console.WriteLine(c.ID + " " + c.Name);
                foreach (Purchase p in c.Purchases)
                    Console.WriteLine("  - purchased a " + p.Description);
            }

            // Notice in the SQL results pane, that this use of DataLoadOptions doesn't prevent
            // the excessive round-tripping that comes from using nested foreach loops to
            // enumerate the results.
            Console.ReadKey();
        }
    }
}
